<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="档案编号">
              <j-input placeholder="请输入档案编号" v-model="queryParam.ptzhbm"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="会员单位">
              <j-input placeholder="请输入会员单位" v-model="queryParam.hydw"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="平台名称">
              <j-input placeholder="请输入平台名称" v-model="queryParam.ptmc"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="网址">
              <j-input placeholder="请输入网址" v-model="queryParam.wz"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="保管人">
              <select-user-by-dep :multi="false" v-model="queryParam.bgr" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep :multi="false" v-model="queryParam.handlerId" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请部门">
              <j-select-depart v-model="queryParam.handlerDeptId"/>
            </a-form-item>
          </a-col>
          <a-col :xl="12" :lg="11" :md="12" :sm="24">
            <a-form-item label="会员有效期始">
              <a-date-picker
                placeholder="请选择开始时间"
                @change="handleChange"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                v-model="queryParam.hyyxqs_begin"
                style="width: 47%" />
              <span class="fontDiy"> 至 </span>
              <a-date-picker
                :disabled-date="disabledDate"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                :default-picker-value="this.queryParam.hyyxqs_begin"
                placeholder="请选择结束时间"
                v-model="queryParam.hyyxqs_end"
                style="width: 47%" />
            </a-form-item>
          </a-col>
          <a-col :xl="12" :lg="11" :md="12" :sm="24">
            <a-form-item label="会员有效期止">
              <a-date-picker
                placeholder="请选择开始时间"
                @change="handleChangeNew"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                v-model="queryParam.hyyxqe_begin"
                style="width: 47%" />
              <span class="fontDiy"> 至 </span>
              <a-date-picker
                :disabled-date="disabledDateNew"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                :default-picker-value="this.queryParam.hyyxqe_begin"
                placeholder="请选择结束时间"
                v-model="queryParam.hyyxqe_end"
                style="width: 47%" />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpOmcPlatformAccountFinal:add')">新增</a-button>-->
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('平台账号档案')"-->
      <!--                :disabled="isDisabledAuth('erpOmcPlatformAccountFinal:export')">导出-->
      <!--      </a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('平台账号档案')" :disabled="isDisabledAuth('erpOmcPlatformAccountFinal:export')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel">
        <!--        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpOmcPlatformAccountFinal:import')">导入-->
        <!--        </a-button>-->
      </a-upload>
      <!-- 高级查询区域 -->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-menu slot="overlay">-->
      <!--          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOmcPlatformAccount:delete')">-->
      <!--            <a-icon type="delete"/>-->
      <!--            删除-->
      <!--          </a-menu-item>-->
      <!--        </a-menu>-->
      <!--        <a-button style="margin-left: 8px"> 批量操作-->
      <!--          <a-icon type="down"/>-->
      <!--        </a-button>-->
      <!--      </a-dropdown>-->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">
                      <!-- {{ item.title }} -->
                      <ellipsis :length="15">{{ item.title }}</ellipsis>
                    </a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <!--BUG#3398小齿轮不应该被隐藏-->
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;margin-top: 20px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="ptzhbm" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-button
            type="primary"
            size="small"
            @click="handleDetail(record)">详情</a-button>
        </span>
        <span slot="modelAndViewRender" slot-scope="text">
          <j-ellipsis :value="text" :length="10"/>
        </span>
      </a-table>
    </div>
    <erp-omc-platform-account-final-modal ref="modalForm" @ok="modalFormOk"></erp-omc-platform-account-final-modal>
    <audit-modal ref="auditModal" @ok="modalFormOk"></audit-modal>
    <select-forward-modal ref="selectForwardModal" @selectFinished="handleForward"></select-forward-modal>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpOmcPlatformAccountFinalModal from './modules/ErpOmcPlatformAccountFinalModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectForwardModal from '@/views/modules/bpm/task/form/SelectForwardModal';
import moment from 'moment';
import Ellipsis from '@/components/Ellipsis'
export default {
  name: 'ErpOmcPlatformAccountFinalList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcPlatformAccountFinalModal,
    SelectUserByDep,
    Ellipsis,
    SelectForwardModal
  },
  data() {
    return {
      dataId: null,
      description: '平台账号档案管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '档案编号',
          align: 'center',
          dataIndex: 'ptzhbm',
          width: 180,
          ellipsis: true,
          scopedSlots: { customRender: 'ptzhbm' }
        },
        {
          title: '会员单位',
          align: 'center',
          dataIndex: 'hydw',
          width: 166,
          ellipsis: true
        },
        {
          title: '平台名称',
          align: 'center',
          dataIndex: 'ptmc',
          width: 166,
          ellipsis: true
        },
        {
          title: '网址',
          align: 'center',
          dataIndex: 'wz',
          width: 166,
          ellipsis: true
        },
        {
          title: '保管人',
          align: 'center',
          dataIndex: 'bgr_dictText',
          width: 90,
          ellipsis: true
        },
        {
          title: '登录名',
          align: 'center',
          dataIndex: 'dlm',
          width: 96,
          ellipsis: true
        },
        {
          title: '密码',
          align: 'center',
          dataIndex: 'mm',
          width: 96,
          ellipsis: true
        },
        {
          title: '会员等级',
          align: 'center',
          dataIndex: 'hydj',
          width: 96,
          ellipsis: true
        },
        {
          title: '会员有效期始',
          align: 'center',
          dataIndex: 'hyyxqs',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          },
          width: 164,
          ellipsis: true
        },
        {
          title: '会员有效期止',
          align: 'center',
          dataIndex: 'hyyxqe',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          },
          width: 164,
          ellipsis: true
        },
        {
          title: 'ca锁密码',
          align: 'center',
          dataIndex: 'casmm',
          width: 196,
          ellipsis: true
        },
        {
          title: 'ca锁个数',
          align: 'center',
          dataIndex: 'casgs',
          width: 96,
          ellipsis: true
        },
        {
          title: 'ca锁有效期始',
          align: 'center',
          dataIndex: 'casyxqs',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          },
          width: 164,
          ellipsis: true
        },
        {
          title: 'ca锁有效期止',
          align: 'center',
          dataIndex: 'casyxqe',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          },
          width: 164,
          ellipsis: true
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'bz',
          width: 196,
          ellipsis: true
        },
        {
          title: '平台注册授权联系人',
          align: 'center',
          dataIndex: 'platformContacts',
          width: 196,
          ellipsis: true
        },
        {
          title: '联系方式',
          align: 'center',
          dataIndex: 'platformContactsTel',
          width: 196,
          ellipsis: true
        },

        {
          title: '申请人',
          align: 'center',
          dataIndex: 'handlerId_dictText',
          width: 164,
          ellipsis: true
        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'handlerDeptId_dictText',
          width: 164,
          ellipsis: true
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status_dictText',
          width: 120,
          ellipsis: true
        },
        // BUG#3398平台账号归档后，不应有删除按钮
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 150,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/final',
        delete: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/delete',
        deleteBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/deleteBatch',
        exportXlsUrl: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/exportXls',
        importExcelUrl: 'api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/importExcel',
        submit: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/submit',
        submitBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/submitBatch',
        revoke: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/revoke',
        revokeBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/revokeBatch',
        counterTrial: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/counterTrial',
        counterTrialBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/counterTrialBatch',
        audit: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/audit',
        auditBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/auditBatch',
        overrule: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/overrule',
        overruleBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/overruleBatch',
        transmit: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/transmit'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    // 查看详情
    getDetail(id) {
      this.$router.push({
        path: `/erp/omc/platformaccount/ErpOmcPlatformAccountFinalListDetail/${id}`
      })
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'mm', text: '密码', dictCode: '' })
      fieldList.push({ type: 'int', value: 'casgs', text: 'ca锁个数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'wz', text: '网址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dlm', text: '登录名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'hydj', text: '会员等级', dictCode: '' })
      fieldList.push({ type: 'date', value: 'casyxqs', text: 'ca锁有效期始' })
      fieldList.push({ type: 'date', value: 'hyyxqs', text: '会员有效期始' })
      fieldList.push({ type: 'string', value: 'ptmc', text: '平台名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jbbm', text: '经办部门', dictCode: '' })
      fieldList.push({ type: 'date', value: 'casyxqe', text: 'ca锁有效期止' })
      fieldList.push({ type: 'string', value: 'hydw', text: '会员单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'casmm', text: 'ca锁密码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bz', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jbr', text: '经办人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'hyyxqe', text: '会员有效期止' })
      fieldList.push({ type: 'string', value: 'auditStatus', text: '状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'ptzhbm', text: '档案编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bgr', text: '保管人', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleChange(value) {
      if (this.queryParam.insuranceEndTime) {
        if ((this.queryParam.insuranceEndTime).diff((this.queryParam.hyyxqs_begin), 'days') < 0) {
          this.queryParam.insuranceEndTime = this.queryParam.hyyxqs_begin
        }
      }
    },
    // 处理转发
    handleTransmit(record) {
      this.dataId = record.id;
      this.$refs.selectForwardModal.select(record);
      this.$refs.selectForwardModal.title = '选择转发人';
    },
    handleForward(data) {
      getAction(this.url.transmit, { dataId: this.dataId, empId: data.empId }).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
          this.loadData();
        } else {
          this.$message.warning(res.message);
        }
      }).catch(error => {
        this.$message.error(res.message);
      });
      },
    disabledDate(current) {
      return current < moment(this.queryParam.hyyxqs_begin).subtract('day')
    },
    handleChangeNew(value) {
      if (this.queryParam.insuranceEndTime) {
        if ((this.queryParam.insuranceEndTime).diff((this.queryParam.hyyxqe_begin), 'days') < 0) {
          this.queryParam.insuranceEndTime = this.queryParam.hyyxqe_begin
        }
      }
    },
    disabledDateNew(current) {
      return current < moment(this.queryParam.hyyxqe_begin).subtract('day')
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
